package com.shen.accountbook.module.home.sortmanagefragment;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.shen.accountbook.R;
import com.shen.accountbook.module.base.BaseHolder;

import java.util.List;

/**
 * author:  shen
 * date:    2018/9/7
 */
public class SortManageAdapter<T> extends RecyclerView.Adapter<BaseHolder> {

    int mCurPosition;
    List<T> mBeanList;
    Context mContext;
    ItemOnClickListen mListen;

    public SortManageAdapter(Context context, List<T> beanList, ItemOnClickListen listen){
        mContext = context;
        mBeanList = beanList;
        mListen = listen;
    }


    @Override
    public BaseHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(mContext).inflate(R.layout.item_sort_manage, parent, false);
        return new SortHolder(v, mContext, mListen, this);
    }

    @Override
    public void onBindViewHolder(BaseHolder holder, int position) {
        if(mBeanList == null || mBeanList.size() <= position){
            return;
        }
        holder.onBindView(mBeanList.get(position), position);
    }

    @Override
    public int getItemCount() {
        return mBeanList == null ? 0 : mBeanList.size();
    }


    interface ItemOnClickListen<T> {
        abstract void itemOnClick(T firstBean);
    }

    public void clear() {
        if(mBeanList != null){
            mBeanList.clear();
            notifyDataSetChanged();
        }
    }

    public void setBeanList(List<T> beanList) {
        if(mBeanList != null){
            mBeanList.clear();
            mBeanList.addAll(beanList);
            notifyDataSetChanged();
        }
    }

    public List<T> getBeanList() {
        return mBeanList;
    }

    public int getCurPosition() {
        return mCurPosition;
    }

    public void setCurPosition(int curPosition) {
        mCurPosition = curPosition;
    }
}
